#include <iostream>

#include <cc++/socket.h>
#include <cc++/thread.h>

using namespace ost;
using namespace std;

class MyThread : public Thread
{
public:
    void run();
};

void MyThread::run()
{
    InetAddress ia("127.0.0.1");
    TCPSocket s(ia, 1208);

    if (!s.isPendingConnection(10000))
    {
	cout << "tcpsocket error" << endl;
    }
    tcpstream tcps(s);
    cout << "accept a connetion" << endl;
    

    while(1)
    {
	Thread::sleep(1000);
    }
    
}

class MyTcpStream : public tcpstream
{
public:
    MyTcpStream() : tcpstream()
    {
        setError(true);
    }    
};

int main()
{
    MyThread t;

    t.start();

    Thread::sleep(1000);
    MyTcpStream tcps;
    tcps.open("127.0.0.1:1208");
    
    cout << "connected" << endl;


    Thread::sleep(5000);
    int i=0;
    while(1)
    {
        tcps.write("01234567890", 10);
	cout << i++ << " ";       	
    }

    return 0;
}

